#include "Precompile.h"
#include "SkySphere.h"
#include "ModelLoader.h"

namespace Graphics{
	SkySphere::SkySphere(std::string& top, std::string& bottom, std::string& left, std::string& right, std::string& front, std::string& back){
		m_texCube = Graphics::GraphicsFactory::createTextureCube(top,bottom,left,right,front,back);

		/*float verts[] = {
			-1.0f, 1.0f, 0.5f,
			1.0f, 1.0f, 0.5f,
			-1.0f, -1.0f, 0.5f,
			-1.0f, -1.0f, 0.5f,
			1.0f, 1.0f, 0.5f,
			1.0f, -1.0f, 0.5f
		};

		Graphics::VertexDataPtr vertData = Graphics::VertexDataPtr(new Graphics::VertexData);
		vertData->m_numVerts = 6;
		vertData->m_byteSize = sizeof(float)*3;
		vertData->m_data = &verts;
		
		m_fullScreenQuad = Graphics::GraphicsFactory::createVertexBuffer(vertData);*/

		Loading::ModelLoader loader;
		loader.setModelFilename(std::string("Cube.bin"));
		ModelPtr model = loader.load();
		m_vertBuff = model->getVertexBuffer(0);
		m_indBuff = model->getIndexBuffer();
		m_indCount = model->getSubMeshList()[0]->m_nuInds;

		m_vertShader = Graphics::GraphicsFactory::m_renderContext->m_materialManager->getVertexShaderIdByName(std::string("VS_SkySphere"));
		m_pixelShader = Graphics::GraphicsFactory::m_renderContext->m_materialManager->getPixelShaderIdByName(std::string("PS_SkySphere"));

		if(m_vertShader == -1 || m_pixelShader == -1){
			LOG_ERROR("Depending on shaders that were not found.");
			assert(0);
		}
	}

	void SkySphere::render(RenderContext* context){
		m_vertBuff->setBuffer(context);
		m_indBuff->setBuffer(context);
		m_texCube->setTexture(context);
		context->m_materialManager->setVertexShader(m_vertShader);
		context->m_materialManager->setPixelShader(m_pixelShader);

		context->m_renderSystem->drawIndexed(m_indCount,0,0);
	}

	void SkySphere::setTextures(std::string& top, std::string& bottom, std::string& left, std::string& right, std::string& front, std::string& back){
		m_texCube = Graphics::GraphicsFactory::createTextureCube(top,bottom,left,right,front,back);
	}

	void SkySphere::fadeToTextures(std::string& top, std::string& bottom, std::string& left, std::string& right, std::string& front, std::string& back, float fadeTime){
		
	}
}